const UserInfo = require('../db/model/UserInfo/UserInfo')

const createUserInfo = async (uid) => {
  const result = UserInfo.create({
    uid
  })

  const data = result.dataValues

  return data
}

const updateUserInfo = async ({firstName, lastName, email, description, gender, picture, city, uid}) => {
  const whereOpt = {
    uid
  }

  const result = await UserInfo.update({
    firstName,
    lastName,
    email,
    description,
    gender,
    picture,
    city,
  },{
    where: whereOpt
  })

  return result[0] > 0
}

const getUserInfoById = async (uid) => {
  const result = await UserInfo.findOne({
    where:{
      uid
    }
  })

  return result
}

module.exports = {
  createUserInfo,
  updateUserInfo,
  getUserInfoById
}
